﻿@model IEnumerable<LandManager.Web.Models.LandInfo>

@{
    ViewBag.Title = "Search";

    var wayList = ViewBag.GetWay;
    var agencyList = ViewBag.Agency;
}

<style type="text/css">
    .divSty {
        padding: 25px 15px 5px 15px;
        font-family: 'Microsoft YaHei';
    }

    .tbSty {
        width: 100%;
        table-layout: fixed;
        border: solid #9D9D9D;
        border-width: 1px 0px 0px 1px;
    }

    .tdSty {
        word-wrap: break-word;
        text-align: center;
        vertical-align: middle;
        border: solid #9D9D9D;
        border-width: 0px 1px 1px 0px;
        font-size: 0.8em;
    }

    .tdheaderSty {
        text-align: center;
        vertical-align: middle;
        border: solid #9D9D9D;
        border-width: 0px 1px 1px 0px;
        font-size: 0.9em;
        height: 35px;
    }

    .headerSty {
        word-wrap: break-word;
        text-align: center;
        vertical-align: middle;
        background-color: #2573c7;
        color: #FFFFFF;
    }

    .selectSty {
        height: 26px;
        width: 210px;
    }

    .textStyle {
        height: 20px;
        width: 190px;
    }

    .texttdSty {
        padding-right: 15px;
    }

    .btnSty {
        width: 120px;
        height: 22px;
        font-size:12px;
        vertical-align: central;
        margin: auto 10px auto 10px;
        vertical-align: central;
        /*margin: auto 10px auto 10px;*/
        text-align: center;
        vertical-align: central;
        text-align: center;
        border: 1px solid #ccc;
        border-radius: 2px;
        background: #DADADA;
        color: #000;
        cursor: auto;
        display: inline-block;
        text-decoration: none;
        padding-top: 5px;
    }

    .btnSty_search {
        width: 32px;
        height: 32px;
        margin: 0px 10px auto auto;
        vertical-align: central;
        background: url(../../images/btn_search_press.png) no-repeat;
        background-size: cover;
        border: 0px;
        cursor: pointer;
    }

    .btnSty_export {
        width: 32px;
        height: 32px;
        margin: 0px 10px auto auto;
        vertical-align: central;
        background: url(../../images/btn_exp_detail_press.png) no-repeat;
        background-size: cover;
        border: 0px;
        cursor: pointer;
    }

    .btnSty_print {
        width: 32px;
        height: 32px;
        margin: 0px 10px auto auto;
        vertical-align: central;
        background: url(../../images/btn_start_press.png) no-repeat;
        background-size: cover;
        border: 0px;
        cursor: pointer;
    }

    .aSty {
        width: 130px;
        height: 32px;
        line-height: 32px;
        vertical-align: central;
        margin: auto auto auto 10px;
        text-align: center;
        vertical-align: central;
        text-align: center;
        background: #2573c7;
        color: #fff;
        border: 0px;
        cursor: pointer;
        display: inline-block;
        text-decoration: none;
    }
    
</style>

<script type="text/javascript" src="~/Scripts/jquery.PrintArea.js"></script>

<script type="text/javascript">
    $(function () {
        $("input#printBtn").click(function () {
            $("div#printDIV").printArea({
                mode: 'popup'
            });
        });


        var D = new Date('2011-06-02T09:34:29+02:00');
        if (!D || +D !== 1307000069000) {
            Date.fromISO = function (s) {
                var day, tz,
                rx = /^(\d{4}\-\d\d\-\d\d([tT ][\d:\.]*)?)([zZ]|([+\-])(\d\d):(\d\d))?$/,
                p = rx.exec(s) || [];
                if (p[1]) {
                    day = p[1].split(/\D/);
                    for (var i = 0, L = day.length; i < L; i++) {
                        day[i] = parseInt(day[i], 10) || 0;
                    };
                    day[1] -= 1;
                    day = new Date(Date.UTC.apply(Date, day));
                    if (!day.getDate()) return NaN;
                    if (p[5]) {
                        tz = (parseInt(p[5], 10) * 60);
                        if (p[6]) tz += parseInt(p[6], 10);
                        if (p[4] == '+') tz *= -1;
                        if (tz) day.setUTCMinutes(day.getUTCMinutes() + tz);
                    }
                    return day;
                }
                return NaN;
            }
        }
        else {
            Date.fromISO = function (s) {
                return new Date(s);
            }
        }

    });



    Date.prototype.Format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1,                 //月份
            "d+": this.getDate(),                    //日
            "h+": this.getHours(),                   //小时
            "m+": this.getMinutes(),                 //分
            "s+": this.getSeconds(),                 //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    function parseISO8601(dateStringInRange) {
        var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/,
            date = new Date(NaN), month,
            parts = isoExp.exec(dateStringInRange);

        if (parts) {
            month = +parts[2];
            date.setFullYear(parts[1], month - 1, parts[3]);
            if (month != date.getMonth() + 1) {
                date.setTime(NaN);
            }
        }
        return date;
    }


    function GenereteQueryCondition() {

        var qKey = $('#queryKey').attr("value");
        var qValue = $('#queryValue').attr("value");

        if (qValue == "") {
            alert("请先输入查询条件");
            return;
        }

        var json = {
            key: qKey,
            value: qValue
        };

        $.ajax({
            url: app + "/Land/Query",
            type: "Post",
            data: json,
            success: function (data) {
                if (data != null && data != '[]' && data.length > 0) {
                    var html = "";
                    var obj = $.parseJSON(data);
                    $.each(obj, function (i, value) {
                        var user = value['land_user'] == null ? "&nbsp;" : value['land_user'];

                        var agency = value['land_agency'] == null ? "" : value['land_agency'];
                        var isIPO = value['land_Is_IPO'] == 1 ? "是" : "否";

                        var location = value['land_location'] == null ? "&nbsp;" : value['land_location'];
                        var isRent = value['land_Is_rent'] == null ? "" : value['land_Is_rent'];
                        var isMortgage = value['land_Is_mortgage'] == null ? "" : value['land_Is_mortgage'];
                        var ownDate = value['land_ownDate'] == null ? "" : value['land_ownDate'];


                        html += "<tr><td class='tdSty'>" + value['ZDBH'] + "</td>";
                        html += "<td class='tdSty'>" + value['land_area'] + "</td>";
                        html += "<td class='tdSty'>" + user + "</td>";

                        //html += "<td class='tdSty'>" + agency + "</td>";


                        html += "<td class='tdSty'>" + isIPO + "</td>";

                        if (ownDate == "") {
                            html += "<td class='tdSty'>" + "&nbsp;" + "</td>";
                        } else {
                            var d = new Date(ownDate);
                            html += "<td class='tdSty'>" + Date.fromISO(ownDate).Format("yyyy-MM-dd") + "</td>";
                        }

                        html += "<td class='tdSty'>" + location + "</td>";
                        html += "<td class='tdSty'>" + isRent + "</td>";
                        html += "<td class='tdSty'>" + isMortgage + "</td>";


                        html += "</tr>";
                    });
                    $("#result").empty();
                    $("#result").append(html);
                }
                else {
                    alert('查询结果为空。');
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus + "     " + errorThrown);
            }
        });
    }

    function Export() {
        
        var qKey = $('#queryKey').attr("value");
        var qValue = $('#queryValue').attr("value");

        if (qValue == "") {
            alert("请先输入查询条件");
            return;
        }

        $("#exportForm").submit();
    }
</script>

<div class="divSty">
    <table style="width: 100%">
        <tr>
            <td style="text-align: left">
                <form id="exportForm" action="~/Land/Export" method="post">
                    <table>
                        <tr>

                            <td class="texttdSty">查询条件</td>
                            <td>
                                <select id="queryKey" name="key" class="selectSty">
                                    <option value="land_getway">土地取得方式</option>
                                    <option value="land_type">土地性质</option>
                                    <option value="land_range">土地区域范围</option>
                                </select>
                            </td>
                            <td>
                                <input id="queryValue" name="value" type="text" class="textStyle" />
                            </td>
                            <td style="width: 50px;"></td>

                            <td>
                                <input id="Button1" class="aSty" type="button" onclick="GenereteQueryCondition();" value="查询" />
                            </td>
                            <td>
                                <a href="#" onclick="Export()" class="aSty">导出excel</a>

                            </td>
                            <td>
                                <input id="printBtn" class="aSty" type="button" value="打印" />
                            </td>
                        </tr>
                    </table>
                </form>
            </td>
            <td>
                @*<div style="float:left;">
                    <table>
                        <tr>
                            <td>
                                <input id="Button1" class="btnSty_search" type="button"  onclick="GenereteQueryCondition();" />
                            </td>
                            <td>
                                <a href="#" onclick="Export()"><img class="btnSty_export" /></a>
                                
                            </td>
                            <td>
                                <input id="printBtn" class="btnSty_print" type="button"/>
                            </td>
                        </tr>
                    </table>
                </div>*@
            </td>
        </tr>
    </table>
</div>

<div id="printDIV">
    <style type="text/css">
        .divSty {
            padding: 25px 15px 5px 15px;
            font-family: 'Microsoft YaHei';
        }

        .tbSty {
            width: 95%;
            table-layout: fixed;
            border: solid #9D9D9D;
            border-width: 1px 0px 0px 1px;
        }

        .tdSty {
            word-wrap: break-word;
            text-align: center;
            vertical-align: middle;
            border: solid #9D9D9D;
            border-width: 0px 1px 1px 0px;
            font-size: 0.8em;
        }

        .tdheaderSty {
            text-align: center;
            vertical-align: middle;
            border: solid #9D9D9D;
            border-width: 0px 1px 1px 0px;
            font-size: 0.9em;
            height: 35px;
        }

        .headerSty {
            word-wrap: break-word;
            text-align: center;
            vertical-align: middle;
            background-color: #2573c7;
            color: #FFFFFF;
        }

        .selectSty {
            height: 26px;
            width: 210px;
        }

        .textStyle {
            height: 20px;
            width: 190px;
        }

        .texttdSty {
            padding-right: 15px;
        }

        .btnSty {
            width: 120px;
            height: 26px;
            vertical-align: central;
            margin: auto 10px auto 10px;
        }
    </style>

    <div class="divSty">

        <table class="tbSty" cellspacing="0">
            <tr class="headerSty">
                <td colspan="8" class="tdheaderSty">查询结果</td>
            </tr>
            <tr class="headerSty">
                <td class="tdheaderSty" style="width: 10%">宗地编号</td>
                <td class="tdheaderSty" style="width: 8%">土地面积</td>
                <td class="tdheaderSty" style="width: 12%">土地使用人</td>
                @*<td class="tdheaderSty" style="width: 12%">所属二级单位</td>*@
                <td class="tdheaderSty" style="width: 13%">是否为上市公司资产</td>
                <td class="tdheaderSty" style="width: 8%">取得时间</td>
                <td class="tdheaderSty" style="width: 12%">宗地位置</td>
                <td class="tdheaderSty" style="width: 6%">是否出租</td>
                <td class="tdheaderSty" style="width: 10%">是否抵押/担保</td>
            </tr>
            <tbody id="result">
                @*<tr>
                        <td class="tdSty">10000001002</td>
                        <td class="tdSty">30000000</td>
                        <td class="tdSty">中国人共和国红色政权所有土地啊哈哈</td>
                        <td class="tdSty">北京市中南海艺术团团体慰问演出长度不够</td>
                        <td class="tdSty">是/否</td>
                        <td class="tdSty">1995/01/09</td>
                        <td class="tdSty">北京市西城区健德门外大街110号</td>
                        <td class="tdSty">否</td>
                        <td class="tdSty">哦</td>
                    </tr>*@
            </tbody>
        </table>
    </div>
</div>
